package com.caipin.service.impl;

/**
 * @Author: zhunian0322@163.com
 * @DateTime: 2021-10-06 12:10
 * @Description: TODO
 */

@Service
public class FaceDatabaseManagementServiceImpl implements FaceDatabaseManagementService {
    @Autowired
    private FaceImageDataDao faceImageDataDao;

    public PageBean<FaceImageData> findFaceDataBaseLike(Integer pageNum, Integer pageSize, String personId, String personType, String personName) {
        Page<FaceImageData> faceImageDataPage = new Page(pageNum.intValue(), pageSize.intValue());
        QueryWrapper<FaceImageData> queryWrapper = new QueryWrapper();
        queryWrapper.eq("action", "update");
        if (null != personId)
            queryWrapper.like("person_id", personId);
        if (null != personType)
            queryWrapper.eq("person_type", personType);
        if (null != personName)
            queryWrapper.like("person_name", personName);
        IPage<FaceImageData> page = this.faceImageDataDao.selectPage((IPage)faceImageDataPage, (Wrapper)queryWrapper);
        PageBean<FaceImageData> pageBean = new PageBean();
        pageBean.setCurrPage(Long.valueOf(page.getCurrent()));
        pageBean.setPageSize(Integer.valueOf(page.getRecords().size()));
        pageBean.setTotalPage(Long.valueOf(page.getPages()));
        pageBean.setTotalCount(Long.valueOf(page.getTotal()));
        pageBean.setList(page.getRecords());
        return pageBean;
    }

    public int delFaceDatabaseListByIds(List<Long> ids) {
        for (Long id : ids)
            delFaceDatabaseById(id);
        return ids.size();
    }

    @Transactional
    public void delFaceDatabaseById(Long id) {
        FaceImageData faceImageData = (FaceImageData)this.faceImageDataDao.selectById(id);
        faceImageData.setAction("delete");
        faceImageData.setTimestamp(Long.valueOf(System.currentTimeMillis() / 1000L));
        this.faceImageDataDao.updateById(faceImageData);
    }
}

